package com.fastjpa.controller;

import java.util.List;

import com.fastjpa.vo.SaveClazzVo;
import org.springframework.web.bind.annotation.*;
import com.fastjpa.vo.ClazzVo;
import com.fastjpa.service.ClazzService;
import com.fastjpa.ResponseData;
import com.efeichong.common.PageData;
import lombok.RequiredArgsConstructor;

/**
* @author admin
* @date 2022/07/17
* @description 班级
*/
@RestController
@RequestMapping("/clazz")
@RequiredArgsConstructor
public class ClazzController {

    private final ClazzService clazzService;

    @GetMapping(value = "/getInfo")
    public ResponseData<ClazzVo> getInfo(@RequestParam("id") Long id) {
        return new ResponseData(clazzService.getInfo(id));
    }

    @GetMapping("/page")
    public ResponseData<PageData<ClazzVo>> page(ClazzVo clazzVo) {
        return new ResponseData(clazzService.selectByPage(clazzVo));
    }

    @PostMapping("insert")
    public ResponseData insert(@RequestBody SaveClazzVo clazzVo) {
        clazzService.insertClazz(clazzVo);
        return new ResponseData();
    }

    @PostMapping("update")
    public ResponseData update(@RequestBody SaveClazzVo clazzVo) {
        clazzService.updateClazz(clazzVo);
        return new ResponseData();
    }

    @GetMapping("/deleteByIds")
    public ResponseData deleteClazzByIds(@RequestParam("ids") List<Long> ids) {
        clazzService.deleteByIds(ids);
        return new ResponseData();
    }

    @GetMapping("/deleteById")
    public ResponseData deleteClazzById(@RequestParam("id") Long id) {
        clazzService.deleteById(id);
        return new ResponseData();
    }

}
